package com.purong.purong.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.purong.purong.R;
import com.purong.purong.bean.SearchTagBean;
import com.purong.purong.util.CommonUtil;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

/**
 * Created by Administrator on 2016/8/29.
 */
public class SearchTagAdapter extends TagAdapter {
    private List<String> tagList;;
    private Context mContext;
    private TagFlowLayout mflowLayout;
    private OnTagClickListener mListener;
    public SearchTagAdapter(Context context, TagFlowLayout flowLayout, List<String> list){
        super(list);
        this.tagList=list;
        this.mContext=context;
        this.mflowLayout=flowLayout;
    }
    public void setOnTagClickListener(OnTagClickListener listener){
        this.mListener=listener;
    }
    @Override
    public View getView(FlowLayout parent, final int position, Object o) {
        View view= LayoutInflater.from(mContext).inflate(R.layout.search_info_tag,mflowLayout,false);
        TextView tv=(TextView) view.findViewById(R.id.search_tag);
        tv.setPadding(CommonUtil.dip2px(mContext,16), CommonUtil.dip2px(mContext,6),CommonUtil.dip2px(mContext,16),CommonUtil.dip2px(mContext,6));

        tv.setText(tagList.get(position));
        tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(mListener!=null){
                    mListener.onTagClick(position);
                }
            }
        });

        return tv;
    }
    public interface OnTagClickListener{
        void onTagClick(int position);
    }
}
